<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>JOB配置Report</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body style="padding: 5px">
<!-- 你的HTML代码 -->
<div class="demoTable">
    <form class="layui-form">
        用户名称：
        <div class="layui-inline">
            <input class="layui-input" name="user" id="user"  autocomplete="off">
        </div>
    </form>
    <hr>
</div>

<table class="layui-hide" id="LAY_table_user" lay-filter="LAY_table_user"></table>

<script src="../layui/layui.all.js"></script>
<script>

    var search = window.location.search ;

    var tableOption =  {
                elem: '#LAY_table_user'
                ,data:[]
                ,cols: [[
                    {  title: '选择', width:60, templet:function(d){
                        var active  =   '<input type="checkbox" name="USER_ID" lay-filter="USER_ID" value="'+d.USER_ID	+'" lay-skin="primary"  >'
                        if(d.JOB_ID){
                            active =   '<input type="checkbox" name="USER_ID"  lay-filter="USER_ID" value="'+d.USER_ID	+'"  lay-skin="primary"   checked  >'
                        }
                        return active
                    } }
                    ,{field:'USER_NAME', title: '工号', width:300,sort: true,templet:function(d){
                        return d.TITLE + " " + d.USER_NAME
                    }}
                    ,{field:'EMAIL', title: 'EMAIL',  width:300, sort: true }
                ]]
                ,id: 'LAY_table_user'
                ,page: true
                ,height: 'full-130'
            }

    //由于模块都一次性加载，因此不用执行 layui.use() 来加载对应模块，直接使用即可：
        ;!function(){
        var layer = layui.layer
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$

        var jobCfgUtil = {
            query:function(table,tableOption,obj){
                $.getJSON("../xxdsqljob/queryUser"+search , obj||{}, function(rst){
                    if(rst.code!=0){
                        layer.alert(rst.msg)
                    }else{
                        tableOption.data = rst.data
                        table.render(tableOption)
                    }
                })
            }
        }

        form.on('checkbox(USER_ID)', function(data){
            var userId = data.value;
            var checkFlag = data.elem.checked ;
            $.getJSON("../xxdsqljob/job2user"+search,{userId:userId,checkFlag:checkFlag},function(rst){
                if(rst.code!=0){
                    layer.alert(rst.msg,{icon:2})
                }else{
                    layer.msg(rst.msg)
                }
            })
        });

        $("#user").bind('input propertychange', function () {
            var user=$(this).val();
            jobCfgUtil.query(table,tableOption,{user:user})
        });

        jobCfgUtil.query(table,tableOption)
    }();

</script>

</body>
</html>
